package com.meichis.yndms.common;

import android.content.Context;

import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;


/**
 * @author szw
 * @version 1.0
 * @date 2020/6/23 17:39
 */

public class GeoUtils {

    public interface DecodeAddressListener{
        void onRegeocodeAddress(String address, int state);
    }

    /**
     * 根据经纬度换算地理位置信息
     * @param context
     * @param Latitude
     * @param Longitude
     */
    public static void GeoSearch(Context context, double Latitude, double Longitude, final DecodeAddressListener listener){
        GeocodeSearch geocodeSearch = new GeocodeSearch(context);
        RegeocodeQuery query = new RegeocodeQuery(new LatLonPoint(Latitude,Longitude),500,GeocodeSearch.AMAP);
        geocodeSearch.getFromLocationAsyn(query);
        geocodeSearch.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {
            @Override
            public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
                if(i == 1000){
                    String address = regeocodeResult.getRegeocodeAddress().getFormatAddress();
                    listener.onRegeocodeAddress(address,i);
                }else {
                    listener.onRegeocodeAddress("",i);
                }
            }

            @Override
            public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
            }
        });
    }
}
